#include "Modifies.h"

Modifies::Modifies()
{
	_size = 0;
	_table = vector<Triple>();
}
BOOLEAN Modifies::setModifies(LINENUM line, INDEX procIndex, INDEX varIndex){
	for(int i=0;i<_size;i++){
		if((_table.at(i).getFirst()==line) && (_table.at(i).getSecond()==procIndex) && (_table.at(i).getThird()==varIndex)){
			return false;
	    }
	}
	Triple t = Triple(line, procIndex, varIndex);
	_table.push_back(t);
	_size++;
	return true;
}

vector <Triple> Modifies::getModifies()
{
	return _table;
}

Triple Modifies::getModifies(INDEX index) {
	return _table.at(index);
}

INTEGER Modifies::getModifiesSize(){
	return _size;
}

vector<INDEX> Modifies::getVariables(LINENUM line)
{
	vector<INDEX> result = vector<INDEX>();
	for(int i=0;i<_size;i++){
		if(_table.at(i).getFirst()==line){
			result.push_back(_table.at(i).getThird());
			}
		}
	return result;
}


vector<LINENUM> Modifies::getLines(INDEX varIndex)
{
	vector<LINENUM> result = vector<INDEX>();
	for(int i=0;i<_size;i++){
		if(_table.at(i).getThird()==varIndex){
			result.push_back(_table.at(i).getFirst());
			}
		}
	return result;

}
	
BOOLEAN Modifies::isModifies(LINENUM line, INDEX varIndex){
	for(int i = 0; i<_size;i++)
	{
		if ((_table.at(i).getFirst()==line) && (_table.at(i).getThird()==varIndex)) {
			return true;
		}
	}
	return false;
}